/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bean.lazy;

import org.ipti.br.tag.dao.HumanFacade;
import org.ipti.br.tag.entity.Human;
import org.ipti.br.tag.entity.enums.Sex;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import javax.inject.Inject;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import org.ipti.br.tag.util.LoggerUtil;

/**
 *
 * @author israel
 */
public class LazyHumanDataModel extends LazyDataModel<Human>{
    
    @Inject private HumanFacade humanDAO;
    
    private Sex sex;

    public LazyHumanDataModel() {
        this.sex = null;
    }

    public LazyHumanDataModel(Sex sex) {
        this.sex = sex;
    }

    public LazyHumanDataModel(HumanFacade humanDAO, Sex sex) {
        this.humanDAO = humanDAO;
        this.sex = sex;
    }
    
    @Override
    public List<Human> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
        return humanDAO.findAllOrder(sex, first, pageSize, filters);
    }

    @Override
    public int getRowCount() {
        return humanDAO.getHumanCount(sex);
    }
    
    public HumanFacade getHumanDAO() {
        return humanDAO;
    }

    public void setHumanDAO(HumanFacade humanDAO) {
        this.humanDAO = humanDAO;
    }

    public Sex getSex() {
        return sex;
    }

    public void setSex(Sex sex) {
        this.sex = sex;
    }
    
}
